package com.bosssoft.hr.train.j2se.collection;

import com.bosssoft.hr.train.j2se.pojo.entity.User;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * HashSetDemo
 */
public class HashSetDemo {
    private Set<User> userHashSet=new HashSet<>();
    User[] users =new User[10];

    /**
     * 创建测试数据
     * @return 用户数组
     */
    public User[] getUsers() {
        for(int i = 0; i < 10; i++){
            users[i] =new User(new Long(i),"BossSoft"+i,"用户"+i);
        }
        return users;
    }

    /**
     * 遍历
     */
    public void visitUserHashSet(){
        users = getUsers();
        for (User user : users){
            userHashSet.add(user);
        }
        User user = new User(new Long(1),"BossSoft"+1,"用户"+1);
        userHashSet.add(user);
        System.out.println("用户数量："+userHashSet.size());
        Iterator<User> userIterator = userHashSet.iterator();
        while (userIterator.hasNext()){
            System.out.println("当前用户："+userIterator.next());
        }
    }
}
